package com.zx.web.servelt;

import com.alibaba.fastjson.JSON;
import com.zx.bean.GoodsType;
import com.zx.web.service.GoodsTypeService;
import com.zx.web.service.impl.GoodsTypeServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author 章鑫
 * @version V1.0
 * @Project 2022-09-05
 * @Package com.zx.web.servelt
 * @Description:
 * @Date 2022/9/14 10:16
 */
@WebServlet("/goodstypeservlet")
public class GoodsTypeServlet extends BaseServlet{
    GoodsTypeService service = new GoodsTypeServiceImpl();

    /**
     * 获取一级分类列表
     * @param req
     * @param resp
     */
    public void goodstypelist(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        List<GoodsType> list = service.goodsTypeL1();
        //转成json
        String listJson = JSON.toJSONString(list);
        resp.setCharacterEncoding("utf-8");
        //传入前端
        resp.getWriter().write(listJson);
    }
}
